Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Arithmetic shift</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Arithmetic_shift"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Arithmetic_shift rootpage-Arithmetic_shift skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Arithmetic shift</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">


<table class="wikitable" style="float:right; clear:right;">
<caption>Arithmetic shift operators in various programming languages and processors
</caption>
<tbody><tr>
<th>Language or processor</th>
<th>Left</th>
<th>Right
</th></tr>
<tr>
<td style="max-width:195px"><a href="ActionScript" title="ActionScript">ActionScript</a> 3, <a href="Java_(programming_language)" title="Java (programming language)">Java</a>, <a href="JavaScript" title="JavaScript">JavaScript</a>, <a href="Python_(programming_language)" title="Python (programming language)">Python</a>, <a href="PHP" title="PHP">PHP</a>, <a href="Ruby_(programming_language)" title="Ruby (programming language)">Ruby</a>, <a href="C_(programming_language)" title="C (programming language)">C</a>, <a href="C%2B%2B" title="C++">C++</a>,<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><a href="D_(programming_language)" title="D (programming language)">D</a>, <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>, <a href="Go_(programming_language)" title="Go (programming language)">Go</a>, <a href="Julia_(programming_language)" title="Julia (programming language)">Julia</a>,<br><a href="Rust_(programming_language)" title="Rust (programming language)">Rust</a> (signed types only)<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>,<br><a href="Swift_(programming_language)" title="Swift (programming language)">Swift</a> (signed types only)<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>note 1<span class="cite-bracket">]</span></a></sup></td>
<td><code> &lt;&lt; </code></td>
<td><code> &gt;&gt; </code>
</td></tr>
<tr>
<td><a href="Ada_(programming_language)" title="Ada (programming language)">Ada</a></td>
<td><code> Shift_Left </code><sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup></td>
<td><code> Shift_Right_Arithmetic </code>
</td></tr>
<tr>
<td><a href="Kotlin_(programming_language)" title="Kotlin (programming language)">Kotlin</a></td>
<td><code> shl </code></td>
<td><code> shr </code>
</td></tr>
<tr>
<td><a href="Fortran" title="Fortran">Fortran</a></td>
<td><code> SHIFTL </code></td>
<td><code> SHIFTA </code><sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>note 2<span class="cite-bracket">]</span></a></sup>
</td></tr>
<tr>
<td><a href="Standard_ML" title="Standard ML">Standard ML</a></td>
<td><code> &lt;&lt; </code></td>
<td><code> ~&gt;&gt; </code>
</td></tr>
<tr>
<td><a href="Verilog" title="Verilog">Verilog</a></td>
<td><code> &lt;&lt;&lt; </code></td>
<td><code> &gt;&gt;&gt; </code><sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>note 3<span class="cite-bracket">]</span></a></sup>
</td></tr>
<tr>
<td><a href="OpenVMS" title="OpenVMS">OpenVMS</a> macro language
</td>
<td colspan="2" align="center">@<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>note 4<span class="cite-bracket">]</span></a></sup>
</td></tr>
<tr>
<td><a href="Scheme_(programming_language)" title="Scheme (programming language)">Scheme</a>
</td>
<td colspan="2" align="center"><code>arithmetic-shift</code><sup id="cite_ref-scheme_9-0" class="reference"><a href="#cite_note-scheme-9"><span class="cite-bracket">[</span>note 5<span class="cite-bracket">]</span></a></sup>
</td></tr>
<tr>
<td><a href="Common_Lisp" title="Common Lisp">Common Lisp</a>
</td>
<td colspan="2" align="center"><code>ash</code>
</td></tr>
<tr>
<td><a href="OCaml" title="OCaml">OCaml</a></td>
<td><code>lsl</code></td>
<td><code>asr</code>
</td></tr>
<tr>
<td><a href="Haskell_(programming_language)" class="mw-redirect" title="Haskell (programming language)">Haskell</a>
</td>
<td colspan="2" align="center"><code>Data.Bits.shift</code><sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">[</span>note 6<span class="cite-bracket">]</span></a></sup>
</td></tr>
<tr>
<td><a href="VHDL" title="VHDL">VHDL</a></td>
<td><code>sla</code><sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">[</span>note 7<span class="cite-bracket">]</span></a></sup></td>
<td><code>sra</code>
</td></tr>
<tr>
<td>Assembly: <a href="Z80" class="mw-redirect" title="Z80">Z80</a></td>
<td><code>SLA</code><sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup></td>
<td><code>SRA</code>
</td></tr>
<tr>
<td>Assembly: <a href="X86_assembly_language" title="X86 assembly language">x86</a></td>
<td><code>SAL</code></td>
<td><code>SAR</code>
</td></tr>
<tr>
<td>Assembly: <a href="Motorola_68000_series" title="Motorola 68000 series">68k</a></td>
<td><code>ASL</code></td>
<td><code>ASR</code>
</td></tr>
<tr>
<td>Assembly: <a href="RISC-V" title="RISC-V">RISC-V</a></td>
<td><code>sll</code>, <code>slli</code><sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup></td>
<td><code>sra</code>, <code>srai</code>
</td></tr></tbody></table>
<p>In <a href="Computer_programming" title="Computer programming">computer programming</a>, an <b>arithmetic shift</b> is a <a href="Bitwise_operation#Bit_shifts" title="Bitwise operation">shift operator</a>, sometimes termed a <b>signed shift</b> (though it is not restricted to signed operands). The two basic types are the <b>arithmetic left shift</b> and the <b>arithmetic right shift</b>. For <a href="Binary_numeral_system" class="mw-redirect" title="Binary numeral system">binary numbers</a> it is a <a href="Bitwise_operation" title="Bitwise operation">bitwise operation</a> that shifts all of the bits of its operand; every bit in the operand is simply moved a given number of bit positions, and the vacant bit-positions are filled in. Instead of being filled with all 0s, as in <a href="Logical_shift" title="Logical shift">logical shift</a>, when shifting to the right, the leftmost bit (usually the <a href="Sign_bit" title="Sign bit">sign bit</a> in signed <a href="Integer" title="Integer">integer</a> representations) is replicated to fill in all the vacant positions (this is a kind of <a href="Sign_extension" title="Sign extension">sign extension</a>).
</p><p>Some authors prefer the terms <i>sticky right-shift</i> and <i>zero-fill right-shift</i> for arithmetic and logical shifts respectively.<sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup>
</p><p>Arithmetic shifts can be useful as efficient ways to perform multiplication or division of signed integers by powers of two. Shifting left by <i>n</i> bits on a signed or unsigned binary number has the effect of multiplying it by 2<sup><i>n</i></sup>. Shifting right by <i>n</i> bits on a <a href="Two's_complement" title="Two's complement">two's complement</a> <i>signed</i> binary number has the effect of dividing it by 2<sup><i>n</i></sup>, but it always rounds down (towards negative infinity). This is different from the way rounding is usually done in signed integer division (which rounds towards 0). This discrepancy has led to bugs in a number of compilers.<sup id="cite_ref-15" class="reference"><a href="#cite_note-15"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>
</p><p>For example, in the <a href="X86_instruction_listings" title="X86 instruction listings">x86 instruction set</a>, the SAR instruction (arithmetic right shift) divides a signed number by a <a href="Power_of_two" title="Power of two">power of two</a>, rounding towards negative infinity.<sup id="cite_ref-FOOTNOTEHyde1996§_6.6.2.2_SAR_16-0" class="reference"><a href="#cite_note-FOOTNOTEHyde1996§_6.6.2.2_SAR-16"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup> However, the IDIV instruction (signed divide) divides a signed number, rounding towards zero. So a SAR instruction cannot be substituted for an IDIV by power of two instruction nor vice versa.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Formal_definition">Formal definition</h2></div>
<p>The formal definition of an arithmetic shift, from <a href="Federal_Standard_1037C" title="Federal Standard 1037C">Federal Standard 1037C</a> is that it is:
</p>
<style data-mw-deduplicate="TemplateStyles:r1244412712">
/* start https://en.wikipedia.org/ */


.mw-parser-output .templatequote{overflow:hidden;margin:1em 0;padding:0 32px}.mw-parser-output .templatequotecite{line-height:1.5em;text-align:left;margin-top:0}@media(min-width:500px){.mw-parser-output .templatequotecite{padding-left:1.6em}}


/* end https://en.wikipedia.org/ */
</style><blockquote class="templatequote"><p>A shift, applied to the representation of a number in a fixed <a href="Radix" title="Radix">radix</a> numeration system and in a <a href="Fixed-point_arithmetic" title="Fixed-point arithmetic">fixed-point</a> representation system, and in which only the characters representing the fixed-point part of the number are moved. An arithmetic shift is usually equivalent to multiplying the number by a positive or a negative integral power of the radix, except for the effect of any rounding; compare the <a href="Logical_shift" title="Logical shift">logical shift</a> with the arithmetic shift, especially in the case of <a href="Floating-point" class="mw-redirect" title="Floating-point">floating-point</a> representation.</p></blockquote>
<p>An important word in the FS 1073C definition is "usually".
</p>
<div class="mw-heading mw-heading3"><h3 id="Non-equivalence_of_arithmetic_right_shift_and_division">Non-equivalence of arithmetic right shift and division</h3></div>
<p>However, arithmetic <i>right</i> shifts are major traps for the unwary, specifically in treating rounding of negative integers. For example, in the usual <a href="Two's_complement" title="Two's complement">two's complement</a> representation of negative integers, −1 is represented as all 1's. For an 8-bit signed integer this is 1111&nbsp;1111. An arithmetic right-shift by 1 (or 2, 3, ..., 7) yields 1111&nbsp;1111 again, which is still −1. This corresponds to rounding down (towards negative infinity), but is not the usual convention for division.
</p><p>It is frequently stated that arithmetic right shifts are equivalent to <a href="Division_(mathematics)" title="Division (mathematics)">division</a> by a (positive, integral) power of the radix (e.g., a division by a power of 2 for binary numbers), and hence that division by a power of the radix can be optimized by implementing it as an arithmetic right shift. (A shifter is much simpler than a divider. On most processors, shift instructions will execute faster than division instructions.) Large number of 1960s and 1970s programming handbooks, manuals, and other specifications from companies and institutions such as <a href="Digital_Equipment_Corporation" title="Digital Equipment Corporation">DEC</a>, <a href="IBM" title="IBM">IBM</a>, <a href="Data_General" title="Data General">Data General</a>, and <a href="American_National_Standards_Institute" title="American National Standards Institute">ANSI</a> make such incorrect statements<sup id="cite_ref-FOOTNOTESteele1977_17-0" class="reference"><a href="#cite_note-FOOTNOTESteele1977-17"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>.
</p><p>Logical right shifts are equivalent to division by a power of the radix (usually 2) only for positive or unsigned numbers. Arithmetic right shifts are equivalent to logical right shifts for positive signed numbers. Arithmetic right shifts for negative numbers in N's complement (usually <a href="Two's_complement" title="Two's complement">two's complement</a>) is roughly equivalent to division by a power of the radix (usually 2), where for odd numbers rounding downwards is applied (not towards 0 as usually expected).
</p><p>Arithmetic right shifts for negative numbers are equivalent to division using rounding towards 0 in <a href="Ones'_complement" title="Ones' complement">ones' complement</a> representation of signed numbers as was used by some historic computers, but this is no longer in general use.
</p>
<div class="mw-heading mw-heading4"><h4 id="Handling_the_issue_in_programming_languages">Handling the issue in programming languages</h4></div>
<p>The (1999) ISO standard for the programming language <a href="C_(programming_language)" title="C (programming language)">C</a> defines the right shift operator in terms of divisions by powers of 2.<sup id="cite_ref-FOOTNOTEISOIEC98991999§_6.5.7_Bitwise_shift_operators_18-0" class="reference"><a href="#cite_note-FOOTNOTEISOIEC98991999§_6.5.7_Bitwise_shift_operators-18"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup> Because of the above-stated non-equivalence, the standard explicitly excludes from that definition the right shifts of signed numbers that have negative values. It does not specify the behaviour of the right shift operator in such circumstances, but instead requires each individual C compiler to define the behaviour of shifting negative values right.<sup id="cite_ref-20" class="reference"><a href="#cite_note-20"><span class="cite-bracket">[</span>note 8<span class="cite-bracket">]</span></a></sup>
</p><p>Like C, C++ had an implementation-defined right shift for signed integers until <a href="C%2B%2B20" title="C++20">C++20</a>. Starting in the C++20 standard, right shift of a signed integer is defined to be an arithmetic shift.<sup id="cite_ref-FOOTNOTEISOCPP202020§_7.6.7_Shift_operators_21-0" class="reference"><a href="#cite_note-FOOTNOTEISOCPP202020§_7.6.7_Shift_operators-21"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Applications">Applications</h2></div>
<p>In applications where consistent rounding down is desired, arithmetic right shifts for signed values are useful. An example is in <a href="Downscaling" title="Downscaling">downscaling</a> raster coordinates by a power of two, which maintains even spacing. For example, right shift by 1 sends 0, 1, 2, 3, 4, 5, ... to 0, 0, 1, 1, 2, 2, ..., and −1, −2, −3, −4, ... to −1, −1, −2, −2, ..., maintaining even spacing as −2, −2, −1, −1, 0, 0, 1, 1, 2, 2, ... In contrast, integer division with rounding towards zero sends −1, 0, and 1 all to 0 (3 points instead of 2), yielding −2, −1, −1, 0, 0, 0, 1, 1, 2, 2, ... instead, which is irregular at 0.
</p>
<div class="mw-heading mw-heading2"><h2 id="Notes">Notes</h2></div>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text">The <code> &gt;&gt; </code> operator in C and C++ is not necessarily an arithmetic shift. Usually it is only an arithmetic shift if used with a signed integer type on its left-hand side. If it is used on an unsigned integer type instead, it will be a <i>logical</i> shift.</span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text">Fortran 2008.</span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text">The Verilog arithmetic right shift operator only actually performs an arithmetic shift if the first operand is signed. If the first operand is unsigned, the operator actually performs a <i>logical</i> right shift.</span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text">In the <a href="OpenVMS" title="OpenVMS">OpenVMS</a> macro language, whether an arithmetic shift is left or right is determined by whether the second operand is positive or negative. This is unusual. In most programming languages the two directions have distinct operators, with the operator specifying the direction, and the second operand is implicitly positive. (Some languages, such as Verilog, require that negative values be converted to unsigned positive values. Some languages, such as C and C++, have no defined behaviour if negative values are used.)<sup id="cite_ref-FOOTNOTEHP2001_7-0" class="reference"><a href="#cite_note-FOOTNOTEHP2001-7"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup></span>
</li>
<li id="cite_note-scheme-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-scheme_9-0">^</a></b></span> <span class="reference-text">In Scheme <code>arithmetic-shift</code> can be both left and right shift, depending on the second operand, very similar to the OpenVMS macro language, although R6RS Scheme adds both <code>-right</code> and <code>-left</code> variants.</span>
</li>
<li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text">The <code>Bits</code> class from Haskell's <code>Data.Bits</code> module defines both <code>shift</code> taking a signed argument and <code>shiftL</code>/<code>shiftR</code> taking unsigned arguments. These are <a href="Isomorphic" class="mw-redirect" title="Isomorphic">isomorphic</a>; for new definitions the programmer need provide only one of the two forms and the other form will be automatically defined in terms of the provided one.</span>
</li>
<li id="cite_note-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-11">^</a></b></span> <span class="reference-text">The VHDL arithmetic left shift operator is unusual. Instead of filling the LSB of the result with zero, it copies the original LSB into the new LSB. While this is an exact mirror image of the arithmetic right shift, it is not the conventional definition of the operator, and is not equivalent to multiplication by a power of 2. In the VHDL 2008 standard this strange behavior was left unchanged (for backward compatibility) for argument types that do not have forced numeric interpretation (e.g., BIT_VECTOR) but 'SLA' for <i>unsigned</i> and <i>signed</i> argument types behaves in the expected way (i.e., rightmost positions are filled with zeros). VHDL's shift left logical (SLL) function does implement the aforementioned 'standard' arithmetic shift.</span>
</li>
<li id="cite_note-20"><span class="mw-cite-backlink"><b><a href="#cite_ref-20">^</a></b></span> <span class="reference-text">The C standard was intended to not restrict the C language to either ones' complement or two's complement architectures. In cases where the behaviours of ones' complement and two's complement representations differ, such as this, the standard requires individual C compilers to document the behaviour of their target architectures. The documentation for <a href="GNU_Compiler_Collection" title="GNU Compiler Collection">GNU Compiler Collection</a> (GCC), for example, documents its behaviour as employing sign-extension.<sup id="cite_ref-FOOTNOTEFSF2008§_4.5_Integers_implementation_19-0" class="reference"><a href="#cite_note-FOOTNOTEFSF2008§_4.5_Integers_implementation-19"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup></span>
</li>
</ol></div>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Cross-reference">Cross-reference</h3></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist reflist-columns references-column-width" style="column-width: 30em;">
<ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://tour.dlang.org/tour/en/gems/bit-manipulation">"Bit manipulation - Dlang Tour"</a>. <i>tour.dlang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2019-06-23</span></span>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators">"Operator Expressions: Arithmetic and Logical Binary Operators"</a>. <i>doc.rust-lang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2022-11-13</span></span>.</cite></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.adaic.org/resources/add_content/standards/12aarm/html/AA-B-2.html">"Annotated Ada 2012 Reference Manual"</a>.</cite></span>
</li>
<li id="cite_note-FOOTNOTEHP2001-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEHP2001_7-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFHP2001">HP 2001</a>.</span>
</li>
<li id="cite_note-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-12">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.z80.info/z80syntx.htm#SLA">"Z80 Assembler Syntax"</a>.</cite></span>
</li>
<li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf">"The RISC-V Instruction Set Manual, Volume I: Unprivileged ISA"</a> <span class="cs1-format">(PDF)</span>. <i><a href="GitHub" title="GitHub">GitHub</a></i>. 2019-12-13. pp.&nbsp;<span class="nowrap">18–</span>20. <a rel="nofollow" class="external text" href="https://ghostarchive.org/archive/20221009/https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf">Archived</a> <span class="cs1-format">(PDF)</span> from the original on 2022-10-09<span class="reference-accessdate">. Retrieved <span class="nowrap">2021-08-07</span></span>.</cite></span>
</li>
<li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text">
Thomas R. Cain and Alan T. Sherman.
<a rel="nofollow" class="external text" href="https://web.archive.org/web/20140109191811/http://www.cisa.umbc.edu/papers/ShermanCryptologia97.pdf">"How to break Gifford's cipher"</a>.
Section 8.1: "Sticky versus Non-Sticky Bit-shifting".
Cryptologia.
1997.</span>
</li>
<li id="cite_note-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-15">^</a></b></span> <span class="reference-text"><cite id="CITEREFSteele_Jr" class="citation web cs1">Steele Jr, Guy. <a rel="nofollow" class="external text" href="http://dspace.mit.edu/bitstream/handle/1721.1/6090/AIM-378.pdf">"Arithmetic Shifting Considered Harmful"</a> <span class="cs1-format">(PDF)</span>. MIT AI Lab. <a rel="nofollow" class="external text" href="https://ghostarchive.org/archive/20221009/http://dspace.mit.edu/bitstream/handle/1721.1/6090/AIM-378.pdf">Archived</a> <span class="cs1-format">(PDF)</span> from the original on 2022-10-09<span class="reference-accessdate">. Retrieved <span class="nowrap">20 May</span> 2013</span>.</cite></span>
</li>
<li id="cite_note-FOOTNOTEHyde1996§_6.6.2.2_SAR-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEHyde1996§_6.6.2.2_SAR_16-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFHyde1996">Hyde 1996</a>, § 6.6.2.2 SAR.</span>
</li>
<li id="cite_note-FOOTNOTESteele1977-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTESteele1977_17-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFSteele1977">Steele 1977</a>.</span>
</li>
<li id="cite_note-FOOTNOTEISOIEC98991999§_6.5.7_Bitwise_shift_operators-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEISOIEC98991999§_6.5.7_Bitwise_shift_operators_18-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFISOIEC98991999">ISOIEC9899 1999</a>, § 6.5.7 Bitwise shift operators.</span>
</li>
<li id="cite_note-FOOTNOTEFSF2008§_4.5_Integers_implementation-19"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEFSF2008§_4.5_Integers_implementation_19-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFFSF2008">FSF 2008</a>, § 4.5 Integers implementation.</span>
</li>
<li id="cite_note-FOOTNOTEISOCPP202020§_7.6.7_Shift_operators-21"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEISOCPP202020§_7.6.7_Shift_operators_21-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFISOCPP202020">ISOCPP20 2020</a>, § 7.6.7 Shift operators.</span>
</li>
</ol></div>
<div class="mw-heading mw-heading3"><h3 id="Sources_used">Sources used</h3></div>
<p><style data-mw-deduplicate="TemplateStyles:r1041539562">
/* start https://en.wikipedia.org/ */


.mw-parser-output .citation{word-wrap:break-word}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}


/* end https://en.wikipedia.org/ */
</style><span class="citation 1037C"><span class="noviewer" typeof="mw:File"><span></span></span>&nbsp;This article incorporates <a href="Copyright_status_of_works_by_the_federal_government_of_the_United_States" title="Copyright status of works by the federal government of the United States">public domain material</a> from <cite class="citation cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20220122224547/https://www.its.bldrdoc.gov/fs-1037/fs-1037c.htm"><i>Federal Standard 1037C</i></a>. <a href="General_Services_Administration" title="General Services Administration">General Services Administration</a>. Archived from <a rel="nofollow" class="external text" href="https://www.its.bldrdoc.gov/fs-1037/fs-1037c.htm">the original</a> on 2022-01-22.</cite></span>
</p>
<style data-mw-deduplicate="TemplateStyles:r1239549316">
/* start https://en.wikipedia.org/ */


.mw-parser-output .refbegin{margin-bottom:0.5em}.mw-parser-output .refbegin-hanging-indents>ul{margin-left:0}.mw-parser-output .refbegin-hanging-indents>ul>li{margin-left:0;padding-left:3.2em;text-indent:-3.2em}.mw-parser-output .refbegin-hanging-indents ul,.mw-parser-output .refbegin-hanging-indents ul li{list-style:none}@media(max-width:720px){.mw-parser-output .refbegin-hanging-indents>ul>li{padding-left:1.6em;text-indent:-1.6em}}.mw-parser-output .refbegin-columns{margin-top:0.3em}.mw-parser-output .refbegin-columns ul{margin-top:0}.mw-parser-output .refbegin-columns li{page-break-inside:avoid;break-inside:avoid-column}@media screen{.mw-parser-output .refbegin{font-size:90%}}


/* end https://en.wikipedia.org/ */
</style><div class="refbegin" style="">
<ul><li><cite id="CITEREFKnuth1969" class="citation book cs1"><a href="Donald_Knuth" title="Donald Knuth">Knuth, Donald</a> (1969). <i><a href="The_Art_of_Computer_Programming" title="The Art of Computer Programming">The Art of Computer Programming</a>, Volume 2 — Seminumerical algorithms</i>. Reading, Mass.: Addison-Wesley. pp.&nbsp;<span class="nowrap">169–</span>170.</cite></li>
<li><cite id="CITEREFSteele1977" class="citation journal cs1">Steele, Guy L. (November 1977). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20170922201035/http://www.dtic.mil/get-tr-doc/pdf?AD=ADA031883">"Arithmetic shifting considered harmful"</a>. <i>ACM SIGPLAN Notices</i>. <b>12</b> (11). New York: ACM Press: <span class="nowrap">61–</span>69. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F956641.956647">10.1145/956641.956647</a>. <a href="Hdl_(identifier)" class="mw-redirect" title="Hdl (identifier)">hdl</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://hdl.handle.net/1721.1%2F6090">1721.1/6090</a></span>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:15420308">15420308</a>. Archived from <a rel="nofollow" class="external text" href="http://www.dtic.mil/get-tr-doc/pdf?AD=ADA031883">the original</a> on September 22, 2017.</cite></li>
<li><cite id="CITEREFHP2001" class="citation book cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20110808085326/http://h71000.www7.hp.com/doc/73final/4515/4515pro_002.html#8_arithmeticshiftoperator">"3.7.1 Arithmetic Shift Operator"</a>. <i>VAX MACRO and Instruction Set Reference Manual</i>. Hewlett-Packard Development Company. April 2001. Archived from <a rel="nofollow" class="external text" href="http://h71000.www7.hp.com/doc/73FINAL/4515/4515pro_002.html#8_arithmeticshiftoperator">the original</a> on 2011-08-08.</cite> <span class="cs1-visible-error citation-comment"><code class="cs1-code">{{cite book}}</code>: </span><span class="cs1-visible-error citation-comment"><code class="cs1-code">|work=</code> ignored (help)</span></li>
<li><cite id="CITEREFISOIEC98991999" class="citation book cs1"><i>Programming languages — C</i>. ISO/IEC 9899:1999. <a href="International_Organization_for_Standardization" title="International Organization for Standardization">International Organization for Standardization</a>. 1999.</cite></li>
<li><cite id="CITEREFHyde1996" class="citation book cs1">Hyde, Randall (1996-09-26). "CHAPTER SIX: THE 80x86 INSTRUCTION SET (Part 3)". <a rel="nofollow" class="external text" href="https://web.archive.org/web/20071123223102/http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-3.html#HEADING3-120"><i>The Art of ASSEMBLY LANGUAGE PROGRAMMING</i></a>. Archived from <a rel="nofollow" class="external text" href="http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-3.html#HEADING3-120">the original</a> on 2007-11-23<span class="reference-accessdate">. Retrieved <span class="nowrap">2007-11-28</span></span>.</cite></li>
<li><cite id="CITEREFFSF2008" class="citation web cs1"><a rel="nofollow" class="external text" href="https://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Integers-implementation.html#Integers-implementation">"C Implementation"</a>. <i>GCC manual</i>. <a href="Free_Software_Foundation" title="Free Software Foundation">Free Software Foundation</a>. 2008.</cite></li>
<li><cite id="CITEREFISOCPP202020" class="citation web cs1"><a rel="nofollow" class="external text" href="https://isocpp.org/files/papers/N4860.pdf">"ISO/IEC 14882:2020(E) – Programming Language C++"</a> <span class="cs1-format">(PDF)</span>. International Organization for Standardization. 2020.</cite></li></ul>
</div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-29" href="https://en.wikipedia.org/wiki/?title=Arithmetic_shift&amp;oldid=1303229778">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>